<?php
session_start(); 

//Stops error messages being disp;layed
//Used as deletes all images and if the image doesnt exist it errors
error_reporting(E_ERROR);

include "webmaster_connect.php";

$product_row_id = $_POST['product_row_id'];
$product_page_name = $_POST['product_name'];

mysql_query("DELETE FROM saddles WHERE id = $product_row_id");

//$_SESSION['new_product_id'] = $new_product_id;

//echo $product_type."<br />";		
//echo $product_catagory."<br />"; 		
//echo $product_sub_catagory."<br />";	
//echo $product_name."<br />"; 			
//echo $product_status."<br />"; 		
//echo $product_cost."<br />"; 			
//echo $product_description."<br />";	
//echo $product_make."<br />"; 			
//echo $product_colour."<br />"; 		
//echo $product_size."<br />"; 			
//echo $product_offer."<br />";

//echo $new_product_id."<br />";


//echo $acronym."<br />";

//Delete the product images

 $ftp_server="ftp.24-7saddles.com";
 $ftp_user_name="z247s504";
 $ftp_user_pass="PxLpCd07";

	
 // set up basic connection
 $conn_id = ftp_connect($ftp_server);

 // login with username and password
 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// change directory to public_html
ftp_chdir($conn_id, 'public_html/images/saddles');

// try to delete $file
	ftp_delete($conn_id, $product_row_id."_1.jpg");
	ftp_delete($conn_id, $product_row_id."_2.jpg");
	ftp_delete($conn_id, $product_row_id."_3.jpg");
	ftp_delete($conn_id, $product_row_id."_4.jpg");

 // set up basic connection
 $conn_id = ftp_connect($ftp_server);

 // login with username and password
 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

    ftp_chdir($conn_id, 'public_html/saddles');
	
	//Gets the product name
	$page_name = $product_page_name;
	//Gets the page name
	$page_name = preg_replace('/\s+/', '_', $page_name);
	
	//Deletes the page
	ftp_delete($conn_id, $page_name.".php");
	
	//echo  $page_name.".php";


header("Location: webmaster_delete_products.php");

?>